<?php
namespace Kuoqi\FileDriver;

//mime与ext参照
class Mime{
	
	static protected $mime = array(
		'.mp3'=>'audio/mp3',
		'.mp4'=>'video/mp4',
		'.jpeg'=>'image/jpeg',
		'.jpg'=>'image/jpeg',
		'.png'=>'image/png',
		'.gif'=>'image/gif',
		'.apk'=>'application/octet-stream',
		'.sb3'=>'application/octet-stream',
		'.pdf'=>'application/pdf',
		'.zip'=>'application/x-zip-compressed',
		'.xls'=>'application/vnd.ms-excel',
		'.xlsx'=>'application/octet-stream',
		//'.xlsx'=>'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
		'.txt'=>'text/plain',
		'.rmvb'=>'application/vnd.rn-realmedia',
	);

    /**
     * 获取的许可type列表
     * @var array
     */
	static protected $mine_list = array(
        'application/octet-stream',
        'application/pdf',
        'application/x-zip-compressed',
        'application/vnd.ms-excel',
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        'application/vnd.rn-realmedia',
        'audio/mp3',
        'video/mp4',
        'image/jpeg',
        'image/jpg',
        'image/png',
        'image/gif',
        'text/plain',

    );
	
	
	public static function mime2ext($mime){
		$map = array_flip(self::$mime);
		return isset($map[$mime])?$map[$mime]:null;
	}
	
	public static function ext2mime($ext){
		return isset(self::$mime[$ext])?self::$mime[$ext]:null;
	}

    /**
     * @return array
     * User kuoqi
     * Datetime 2022/3/8 11:30
     * Remark 获取mime列表信息
     */
	static public function mimelist(){
	    $arr = array();
        foreach (self::$mine_list as $v){
            $arr[] = $v;
        }
        return $arr;
    }

    /**
     * 获取关于图片的mime列表
     * @return array
     */
    static public function mimeimagelist(){
        return array(
            'image/jpeg',
            'image/jpg',
            'image/png',
            'image/gif',
        );
    }
}